<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>/net/nas/exports/srv/www/webapps/Projects/Java/CS222/Seminar_5/AssignmentThree/src/applet1.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;applet1.java</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Display a sample applet in an embeded applet window, or within the</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Java appletviewer application.</font><font color="#0000ff">&nbsp;Write a report that explains the</font><br>
<font color="#0000ff">&nbsp;* relationship best.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Applet1.html has-a applet1 class (Composition). The Applet1.html page and</font><br>
<font color="#0000ff">&nbsp;* the applet1 class have the same lifetime, and custody. When the web page</font><br>
<font color="#0000ff">&nbsp;* is rendered, the applet lives, when the web page is closed or the browser</font><br>
<font color="#0000ff">&nbsp;* is closed, the applet closes (terminates) with the Applet1.html page.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Therefore, the relationship between the html page and the embeded applet</font><br>
<font color="#0000ff">&nbsp;* is a 'has-a' relationship (Compostion).</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* The applet1 class inherits from it's parent Applet. Applet is part of the</font><br>
<font color="#0000ff">&nbsp;* java.applet package, and it's parent is Panel, and has one known subclass</font><br>
<font color="#0000ff">&nbsp;* JApplet. Applet implements the following interfaces: ImageObserver,</font><br>
<font color="#0000ff">&nbsp;* MenuContainer, Serializable, and Accessible.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Our applet1 class has an &quot;strong is-a&quot; relationship with Applet, and Applet</font><br>
<font color="#0000ff">&nbsp;* with it's parent and so-forth. Which means our applet1 inherited all</font><br>
<font color="#0000ff">&nbsp;* the methods and properties thorougout the hierarchical tree.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* One particular overridden method 'paint' is inherited from the</font><br>
<font color="#0000ff">&nbsp;* java.awt.Component class. The paint method has one parameter 'Graphics'</font><br>
<font color="#0000ff">&nbsp;* which according to the Java documentation &quot;Programs must use this Graphics</font><br>
<font color="#0000ff">&nbsp;* object (or one derived from it) to render output. They are free to change</font><br>
<font color="#0000ff">&nbsp;* the state of the Graphics object as necessary.&quot;</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* As implemented, the relationship between applet1 and the Graphics object</font><br>
<font color="#0000ff">&nbsp;* appears to be associative. The class applet1 does not have a property to</font><br>
<font color="#0000ff">&nbsp;* retain a reference to the Graphics object, and therefore does not have</font><br>
<font color="#0000ff">&nbsp;* a 'has-a' relationship (composition).</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Further more, the lifetime of applet1 and the Graphics object are different.</font><br>
<font color="#0000ff">&nbsp;* The applet object lives even if the paint method isn't invoked. The applet</font><br>
<font color="#0000ff">&nbsp;* is dependent on the Graphics object to function properly, but are truly</font><br>
<font color="#0000ff">&nbsp;* independent objects. I believe this is a special form of association</font><br>
<font color="#0000ff">&nbsp;* called 'dependency.'</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Our applet1 class has complete custody of this Graphics object. Custody is</font><br>
<font color="#0000ff">&nbsp;* neither shared nor passed to another Applet class. Each applet has it's</font><br>
<font color="#0000ff">&nbsp;* own instance of the Graphics object, and therefore renders it's own</font><br>
<font color="#0000ff">&nbsp;* graphics component.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* After looking at the implementation, lifetime and custody, I would have to</font><br>
<font color="#0000ff">&nbsp;* say the relationship between applet1 and Graphics is an associative</font><br>
<font color="#0000ff">&nbsp;* 'uses-a' relationship. The Applet uses-a Graphics component to render</font><br>
<font color="#0000ff">&nbsp;* the graphic display within the applet viewer window.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;&nbsp;John Thomason</font><br>
<font color="#0000ff">&nbsp;* Course:&nbsp;&nbsp;CS222 Java II</font><br>
<font color="#0000ff">&nbsp;* Seminar: 5</font><br>
<font color="#0000ff">&nbsp;* Assign:&nbsp;&nbsp;3</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;*/</font><br>
<font color="#a020f0">import</font>&nbsp;java.awt.*;<br>
<font color="#a020f0">import</font>&nbsp;java.applet.*;<br>
<br>
&nbsp;<font color="#0000ff">// new class extended from Applet superclass</font><br>
<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;applet1 <font color="#2e8b57"><b>extends</b></font>&nbsp;Applet<br>
{<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a020f0">@Override</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;paint(Graphics g)<br>
&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setBackground(Color.BLUE);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.setColor(Color.WHITE);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.setFont(<font color="#a52a2a"><b>new</b></font>&nbsp;Font(Font.SERIF,Font.PLAIN,<font color="#ff00ff">14</font>));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.drawString(<font color="#ff00ff">&quot;Hello&quot;</font>,<font color="#ff00ff">15</font>,<font color="#ff00ff">20</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.drawString(<font color="#ff00ff">&quot;From Your Instructor&quot;</font>,<font color="#ff00ff">15</font>,<font color="#ff00ff">40</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.drawString(<font color="#ff00ff">&quot;Sofia Saleem&quot;</font>,<font color="#ff00ff">15</font>,<font color="#ff00ff">60</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.setFont(<font color="#a52a2a"><b>new</b></font>&nbsp;Font(Font.SANS_SERIF,Font.BOLD,<font color="#ff00ff">14</font>));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.drawString(<font color="#ff00ff">&quot;Editor: John Thomason&quot;</font>, <font color="#ff00ff">15</font>,<font color="#ff00ff">85</font>);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}<br>
</font></body>
</html>
